// ----------------------------------------------整体-----------------------------------

import Cookie from './cookie.js'
import Api from  './api.js'
import WApi from  '../wj/api.js'
import Base_api from "./Base_api.js";


new Vue({
    el:'#host',
    data(){
        return{
            hostShow:[],                            //显示的数据
            carezh:[],                              //关注的账号
            fanszh:[],                              //账号的粉丝
            uinfos:[],                             //当前用户的所有信息
            search:'',                            //搜索框内容
        }
    },
    methods:{
       async info(){
           let zh = sessionStorage.getItem("zh")
           let allinfo = await WApi.login()
           for(let i=0;i<allinfo.length;i++){
               if(allinfo[i].zh==zh){
                   this.uinfos=allinfo[i]
                   break
               }
           }
           //调用关注表的内容
           let careinfo = await WApi.careInfo()
           let caremsg = careinfo.data
           //获取
           for (let i=0;i<caremsg.length;i++){
               for (let j=0;j<allinfo.length;j++){
                   //关注的账号
                   if(caremsg[i].user_zh==zh){
                       if(caremsg[i].care_zh==allinfo[j].zh){
                           this.carezh.push(allinfo[j])
                       }
                   }
                   //粉丝的账号
                   if(caremsg[i].care_zh==zh){
                       if(caremsg[i].user_zh==allinfo[j].zh){
                           this.fanszh.push(allinfo[j])
                       }
                   }
               }
           }
           this.indata()
       },
        async indata(){
           this.hostShow=await Base_api.getHostshow(this.uinfos.id)
        },
        async management(fanjuId) {
            Cookie.setCookie("aid",fanjuId, "d1")     //----记录下来当前选中的饭局id
            location.href='Management.html'
        }
    },
    mounted(){
        if(sessionStorage.getItem("zh")==null){
            this.$alert('请先登录', '系统提示', {
                confirmButtonText: '确定',
                callback: action => {
                    this.$message({
                        type: 'warning',
                        message: '即将跳转到登录界面...'
                    });
                    location.href='./login.html'
                }
            });
        }else {
            this.info()
        }
    }
})

